<?php
/**
 * Login_Data_Getuserdata
 * get user data
 * @author Adrian Stolarski
 */
class Login_Data_Getloggeddata implements Login_Data_Mainable, Login_Data_Preparable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     * 
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * get new session data
     * 
     * @param array $variables
     * @return array $session_data
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        $this->database->query();
        $session_data = $this->database->fetch('array');
        return $session_data;
    }
    
    /**
     * prepare_query()
     * prepare query 
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $user_id = $variables['user_id'];
        $this->database_query = "SELECT "
                . "user_object.user_id, user_object.access_level_id, user_object.language_id "
                . "FROM "
                . "user_object "
                . "WHERE "
                . "user_object.user_id='$user_id' "
                . "LIMIT 1;";
    }

}
